﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EzDesk.Message.Model
{
    public class MessageContent
    {
        public MessageContent() { }

        public MessageContent(string message)
        {
            MessageText = message;
        }

        /// <summary>
        /// 消息ID
        /// </summary>
        public Guid MessageId { get; set; }

        /// <summary>
        /// 消息内容
        /// </summary>
        public string MessageText { get; set; }


        /// <summary>
        /// 是否需要为消息做摘要
        /// </summary>
        public bool IsNeedSummrize
        {
            get
            {
                return MessageText.Length > 50;
            }
        }

        /// <summary>
        /// 消息摘要
        /// </summary>
        public string SummrizedMessage
        {
            get
            {
                if (IsNeedSummrize)
                {
                    return summrizeMessage(MessageText);
                }
                else
                {
                    return MessageText;
                }
            }
        }

        /// <summary>
        /// 获得消息摘要
        /// </summary>
        /// <param name="MessageText"></param>
        /// <returns></returns>
        private string summrizeMessage(string MessageText)
        {
            int totalLength = 50;
            return string.Format(
                "{0}...{1}",
                MessageText.Substring(0, totalLength - 6),
                MessageText.Substring(MessageText.Length - 3, 3)
                );
        }
    }
}
